<?php

include "log4php/Logger.php";
include "bootstrap.php";

abstract class BeObject {

  const ROOTPATH = "C:/Program Files/wamp/framework/beobject/";

  /** @var Logger The logger. */
  public static $LOG = null;

  /**
   * This function init the beobject framework.<br />
   * It's used as the autoload function, registered by spl_autoload_register.
   * @param string $classname The class name required.
   */
  public static function init($classname) {
    Logger::configure("beobject/logs/log4php.xml");
    self::$LOG = Logger::getLogger("beobject");

    switch (strtolower($classname)) {
      case "arithmeticexception" :
      case "arrayindexoutofboundsexception" :
      case "beobjectexception" :
      case "classcastexception" :
      case "eofexception" :
      case "filenotfoundexception" :
      case "illegalargumentexception" :
      case "illegalstateexception" :
      case "indexoutofboundsexception" :
      case "ioexception" :
      case "malformedurlexception" :
      case "nosuchelementexception" :
      case "nullpointerexception" :
      case "numberformatexception" :
      case "beobjectruntimeexception" :
      case "unknownhostexception" :
      case "validationexception" :
      case "businessexception" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "exceptions/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "exceptions/" . strtolower($classname) . ".class.php";
        break;

      case "file" :
      case "folder" :
      case "streamreader" :
      case "streamwriter" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "io/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "io/" . strtolower($classname) . ".class.php";
        break;

      case "ifile" :
      case "ifolder" :
      case "istreamreader" :
      case "istreamwriter" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "io/interfaces/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "io/interfaces/" . substr(strtolower($classname), 1) . ".interface.php";
        break;

      case "iboolean" :
      case "iinteger" :
      case "istring" :
      case "ichar" :
      case "ifloat" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "primary/interfaces/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "primary/interfaces/" . substr(strtolower($classname), 1) . ".interface.php";
        break;

      case "string" :
      case "integer" :
      case "boolean";
      case "char" :
      case "float" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "primary/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "primary/" . strtolower($classname) . ".class.php";
        break;

      case "archive" :
      case "archiveinfo" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "resources/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "resources/" . strtolower($classname) . ".class.php";
        break;

      case "isocket" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "net/interfaces/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "net/interfaces/" . substr(strtolower($classname), 1) . ".interface.php";
        break;

      case "httppost" :
      case "socket" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "net/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "net/" . strtolower($classname) . ".class.php";
        break;

      case "controller" :
      case "model" :
      case "view" :
      case "enginemodel" :
      case "validatorhelper" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "mvc/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "mvc/" . strtolower($classname) . ".class.php";
        break;

      case "ivalidatorhelper" :
      case "ivalidator" :
      case "icontroller" :
      case "idataaccessobject" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "mvc/interfaces/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "mvc/interfaces/" . substr(strtolower($classname), 1) . ".interface.php";
        break;

      case "script" :
      case "arraylist" :
      case "datetimeparser" :
      case "dateutils" :
      case "bcmath" :
      case "ctype" :
      case "iniparser" :
      case "mcrypt" :
      case "stringutils" :
      case "cracker" :
      case "math" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "utils/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "utils/" . strtolower($classname) . ".class.php";
        break;

      case "swiftcode" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "utils/accounting/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "utils/accounting/" . strtolower($classname) . ".class.php";
        break;

      case "iswiftcode" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "utils/accounting/interfaces/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "utils/accounting/interfaces/" . substr(strtolower($classname), 1) . ".interface.php";
        ;
        break;

      case "iarraylist" :
      case "ictype" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "utils/interfaces/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "utils/interfaces/" . substr(strtolower($classname), 1) . ".interface.php";
        ;
        break;

      case "template" :
      case "cookie" :
      case "json" :
      case "serverutility" :
      case "uploadedfile" :
      case "uri" :
      case "httputility" :
      case "postedfile" :
      case "rss" :
      case "rssitem" :
      case "uriinformations" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "web/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "web/" . strtolower($classname) . ".class.php";
        break;

      case "mailmessage" :
      case "mailattachment" :
      case "smtpmail" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "web/mail/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "web/mail/" . strtolower($classname) . ".class.php";
        break;

      case "isqlserver" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "sql/interfaces/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "sql/interfaces/" . substr(strtolower($classname), 1) . ".interface.php";
        break;

      case "mssql" :
      case "mysql" :
      case "odbclink" :
      case "sqlserver" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "sql/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "sql/" . strtolower($classname) . ".class.php";
        break;

      case "iconfigurator" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "servers/interfaces/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "servers/interfaces/" . substr(strtolower($classname), 1) . ".interface.php";
        break;

      case "apache" :
      case "configurator" :
      case "iis" :
      case "ldap" :
      case "nsapi" :
      case "server" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . "servers/" . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . "servers/" . strtolower($classname) . ".class.php";
        break;

      case "base" :
        BeObject::$LOG->trace("requiring " . self::ROOTPATH . strtolower($classname) . ".class.php");
        require_once self::ROOTPATH . strtolower($classname) . ".class.php";
        break;

      default :
        BeObject::$LOG->fatal($classname . " class not found");
        throw new Exception($classname . " class not found");
    }
  }

}

/**
 * This function allows you to import a class or a full namespace.
 * @param string $namespace The class or namespace to import.
 * @deprecated You must no more use this function since the autoload was implemented.
 */
function Imports($namespace) {
  if (is_string($namespace)) {
    if (strpos($namespace, ".class.php") !== FALSE) {
      if (file_exists(BeObject::ROOTPATH . $namespace))
        require_once BeObject::ROOTPATH . $namespace;
      else
        throw new Exception("\$namespace file does not exists", 0);
    }
    else {
      $ar = scandir(BeObject::ROOTPATH . $namespace);

      if (is_array($ar)) {
        for ($i = 0; $i < count($ar); ++$i)
          if ($ar[$i] != "." && $ar[$i] != "..")
            if (file_exists(BeObject::ROOTPATH . $namespace . "/" . $ar[$i]) && strpos($ar[$i], ".php") !== FALSE)
              require_once BeObject::ROOTPATH . $namespace . "/" . $ar[$i];
      }
      else
        throw new Exception("\$namespace namespace does not exists", 0);
    }
  }
  else
    throw new Exception("\$namespace parameter should be a string", 0);
}

?>